package com.axzhengxin.platform.common.service;

import cn.hutool.core.util.StrUtil;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * IBizCommonService
 * 安信小宝、关联图谱、信用分、黑名单功能服务
 *
 * @author jiangnan
 * @date 2021/3/23
 */
public interface IBizCommonService {

    /**
     * 获取关联图谱跳转地址及参数
     *
     * @param customerName 企业名称
     * @return 参数集合
     */
    GraphRedirectResponse graphRedirect(String customerName);

    /**
     * 查询黑名单规则触发列表
     *
     * @param customerId 客户ID
     * @return 触发结果
     */
    BlackNameListResponse blackNameList(String customerId);

    /**
     * 获取安信评分跳转地址
     *
     * @return 响应对象
     */
    AxScoreRedirectResponse axScoreRedirect();

    /**
     * 获取客户的信用报告
     *
     * @param customerId 客户编号
     * @return 响应对象
     */
    CreditReportResponse creditReport(String customerId);

    @Accessors(chain = true)
    @Data
    class GraphRedirectResponse {

        private String username;

        private String channel;

        private String name;

        private String url;

    }

    @Accessors(chain = true)
    @Data
    class BlackNameListResponse {

        /**
         * 状态码
         */
        private String code;

        /**
         * 响应消息
         */
        private String message;

        /**
         * 触发规则列表
         */
        private List<String> rules;

        public static BlackNameListResponse unauthorized() {
            return new BlackNameListResponse()
                    .setCode("200100")
                    .setMessage("未查询到该企业的综合授权文件，请联系客户在中小微企业综合金融服务平台进行补授权！");
        }

        public static BlackNameListResponse init(List<String> rules) {
            return new BlackNameListResponse()
                    .setCode("100100")
                    .setRules(rules);
        }

        public static BlackNameListResponse error() {
            return new BlackNameListResponse()
                    .setCode("300100")
                    .setMessage("未能获取黑名单信息");
        }

    }

    @Accessors(chain = true)
    @Data
    class AxScoreRedirectResponse {

        private String url;

    }

    @Accessors(chain = true)
    @Data
    class CreditReportResponse {

        /**
         * 报告状态码
         */
        private String code;

        /**
         * 报告消息，仅用于报错提醒
         */
        private String message;

        /**
         * 信用报告内容
         */
        private String reportContent;

        public static CreditReportResponse init(String reportContent) {
            if (StrUtil.isNotBlank(reportContent)) {
                return new CreditReportResponse()
                        .setCode("100100")
                        .setReportContent(reportContent);
            } else {
                return new CreditReportResponse()
                        .setCode("300100")
                        .setReportContent("未能获取信用报告");
            }
        }

        public static CreditReportResponse unauthorized() {
            return new CreditReportResponse()
                    .setCode("200100")
                    .setMessage("未查询到该企业的综合授权文件，请联系客户在中小微企业综合金融服务平台进行补授权！");
        }

    }

}
